<?php
/**
 * PollingPlanController.php
 *
 * @copyright   2023 thingsworld.com.cn - All Rights Reserved
 * @link        http://thingsworld.com.cn/
 * @author      stiffer.chen <chenl@thingsworld.com.cn>
 * @created     2023-09-06 15:39:14
 * @modified    2023-09-06 15:39:14
 *
 */

namespace App\Http\Controllers;

use App\Repositories\PollingPlanRepo;
use Illuminate\Http\Request;

class PollingPlanController extends BaseModuleController
{
    public function params()
    {
        try {
            $data = PollingPlanRepo::params();
            return message('获取成功', true, $data);
        } catch (\Exception $e) {
            return message($e->getMessage(), false);
        }
    }

    public function index(Request $request)
    {
        try {
            $data = PollingPlanRepo::getList();
            $export = intval(\request('export', ''));
            if ($export) {
                return message('获取成功', true, $data);
            }
            return list_message('获取成功', true, $data);
        } catch (\Exception $e) {
            return message($e->getMessage(), false);
        }
    }

    public function show(Request $request, $id)
    {
        try {
            $data = PollingPlanRepo::getDetail($id);
            return message('获取成功', true, $data);
        } catch (\Exception $e) {
            return message($e->getMessage(), false);
        }
    }

    public function store(Request $request)
    {
        try {
            $data = PollingPlanRepo::store();
            return message('保存成功', true, $data);
        } catch (\Exception $e) {
            return message($e->getMessage(), false);
        }
    }

    public function logs(Request $request, $id)
    {
        try {
            $logs = PollingPlanRepo::logs($id);
            return list_message('获取成功', true, $logs);
        } catch (\Exception $e) {
            return message($e->getMessage(), false);
        }
    }

    public function update(Request $request, $id)
    {
        try {
            $data = PollingPlanRepo::update($id);
            return message('修改成功', true, $data);
        } catch (\Exception $e) {
            return message($e->getMessage(), false);
        }
    }

    public function destroy(Request $request, $id)
    {
        try {
            PollingPlanRepo::destroy($id);
            return message('删除成功', true);
        } catch (\Exception $e) {
            return message($e->getMessage(), false);
        }
    }

    public function pause(Request $request, $id)
    {
        try {
            $data = PollingPlanRepo::pause($id);
            return message('暂停成功', true, $data);
        } catch (\Exception $e) {
            return message($e->getMessage(), false);
        }
    }

    public function start(Request $request, $id)
    {
        try {
            $data = PollingPlanRepo::start($id);
            return message('开始成功', true, $data);
        } catch (\Exception $e) {
            return message($e->getMessage(), false);
        }
    }
}